home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / SAT 2.1.2 / Zkrolly ƒ / Zkrolly.c < prev    next >
Encoding:
Text File  |  1994-06-26  |  2.9 KB  |  120 lines  |  [TEXT/KAHL]

  1.  
  2. //• C translation from Pascal source file: Zkrolly.p
  3.  
  4. //• main Zkrolly;
  5. #include "SAT.h"
  6.  
  7. extern void        InitXprite(void);
  8. extern pascal void        SetupXprite(SpritePtr me);
  9. extern pascal void        HandleXprite(SpritePtr me);
  10. extern void        InitZprite(void);
  11. extern pascal void        SetupZprite(SpritePtr me);
  12. extern pascal void        HandleZprite(SpritePtr me);
  13.  
  14.     
  15. SpritePtr ignoresp, zp;
  16. WindowPtr Zwind;
  17. Rect r;
  18.  
  19. enum {
  20.     scrollSizeH = 200,
  21.     scrollSizeV = 200
  22. };
  23.  
  24. Boolean IsOptionPressed()
  25. {
  26.     KeyMap km;
  27.  
  28.     GetKeys(&km);
  29.     return (km[1] & 4)!=0;
  30. }
  31.  
  32. pascal Boolean Zyncho()
  33. {
  34.     Rect where, dest;
  35.     
  36.     where.top = zp->position.v;
  37.     where.left = zp->position.h;
  38.     where.left = where.left - (scrollSizeH >> 1);
  39.     where.top = where.top - (scrollSizeV >> 1);
  40.     if (where.left < 0)
  41.         where.left = 0;
  42.     if (where.top < 0)
  43.         where.top = 0;
  44.     if (where.left + scrollSizeH > gSAT.offSizeH)
  45.         where.left = gSAT.offSizeH - scrollSizeH;
  46.     if (where.top + scrollSizeV > gSAT.offSizeV)
  47.         where.top = gSAT.offSizeV - scrollSizeV;
  48.     where.bottom = where.top + scrollSizeV;
  49.     where.right = where.left + scrollSizeH;
  50.     SetRect(&dest, 0, 0, scrollSizeV, scrollSizeH);
  51.     
  52.     SATCopyBitsToScreen(gSAT.offScreen, where, dest, IsOptionPressed());
  53. /* Note that there's hardly any speed difference between fast and safe mode when copying areas this big!*/
  54.  
  55.     return true; //• Tell SAT not to draw on-screen: we do that ourselves!.
  56. }
  57.  
  58. void SetupZwind()
  59. {
  60.     Rect zr;
  61.     SysEnvRec wrld;
  62.     
  63.     //• Since SAT hasn't been initialized, we can't use colorFlag but 
  64.     //• have to check environs ourselves.
  65.     if ( noErr != SysEnvirons(1, &wrld))
  66.         ;//• ignore errors.
  67.     SetRect(&zr, 20, 30, 20 + scrollSizeV, 30 + scrollSizeH);
  68.     if ( wrld.hasColorQD )
  69.         Zwind = NewCWindow(0L, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
  70.     else
  71.         Zwind = NewWindow(0L, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
  72. }
  73.  
  74.  
  75. main ()
  76. {
  77. /* ThinkC doesn't initialize automatically, so we must do that ourselves? */
  78.  
  79.     MaxApplZone ();
  80.     FlushEvents (everyEvent - diskMask, 0 );
  81.     InitGraf (&thePort);
  82.     InitFonts ();
  83.     InitWindows ();
  84.     InitMenus ();
  85.     TEInit ();
  86.     InitDialogs (nil);        /* no restart proc */
  87.     InitCursor ();
  88.  
  89.     MoreMasters ();
  90.     MoreMasters ();
  91.  
  92. /* End of initializations */
  93.  
  94.     SetupZwind ();
  95.  
  96.     SetRect(&r, 0, 0, 510, 340);
  97.     CustomInitSAT(128, 129, &r, Zwind, 0L, false, false, false, true, false);
  98.     InitXprite ();
  99.     InitZprite ();
  100.     ShowWindow(gSAT.wind);
  101.     SelectWindow(gSAT.wind);
  102.     SATInstallSynch(&Zyncho);
  103.     zp = NewSprite(0, 90, 70, &SetupZprite);
  104.     ignoresp = NewSprite(0, 120, 100, &SetupXprite);
  105.     ignoresp = NewSprite(0, 200, 160, &SetupXprite);
  106.     do
  107.     {
  108.         RunSAT(IsOptionPressed());
  109.     } while (! Button ());
  110.  
  111.     //• WARNING! It seems like we mess up the current device somewhere. 
  112.     //• Probably a bug in SAT (where the device setting isn't perfect 
  113.     //• yet). Let's set port and device to something nice and safe!.
  114.     SetPort(gSAT.wind);
  115.     if (colorFlag)
  116.         SetGDevice(GetMainDevice ());
  117. /* Finally, make sure we dispose of the sound channel. */
  118.     SATSoundShutup();
  119. }
  120.